package yl.hs.bmipfull.controllers.system;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import yl.hs.bmipfull.controllers.ControllerBase;
import yl.hs.bmipfull.service.system.IWHNetEquipmentService;
import yl.hs.bmipfull.viewmodels.PageQuery;
import yl.hs.bmipfull.viewmodels.SubmitModel;
import yl.hs.bmipfull.viewmodels.WebResult;

/**
 * 作用:  网络设备信息表控制层<br/>
 * 创建时间: 2021年06月04日 15时16分51秒 <br/>
 *
 * @author 吴高丰
 */
@Api(value = "网络设备信息表Web接口", tags = "系统管理——网络设备信息表操作")
@RequestMapping(value = "/api/system/wHNetEquipment")
@RestController
public class WHNetEquipmentController extends ControllerBase {
    @Autowired
    IWHNetEquipmentService service;
    @ApiOperation(value = "查询网络设备信息表", notes = "查询网络设备信息表")
    @RequestMapping(value = "", method = RequestMethod.POST)
    public WebResult queryList(
            @ApiParam(value = "查询条件") @RequestBody PageQuery pageQuery) {
        try {
            return success("查询成功", service.queryList(pageQuery));
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "根据地磅编号查询设备信息表", notes = "根据地磅编号查询设备信息表")
    @RequestMapping(value = "/weigh", method = RequestMethod.GET)
    public WebResult queryListByWeighbridgeSn(
            @ApiParam(value = "查询条件") @RequestParam String mainSn) {
        try {
            return success("查询成功",
                    service.queryListByDBSn(mainSn));
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "查询网络设备信息表", notes = "根据网络设备信息表编号查询网络设备信息表")
    @RequestMapping(value = "/{sn}", method = RequestMethod.GET)
    public WebResult findBySn(
            @ApiParam(value = "编号") @PathVariable String sn) {
        return success("查询成功", service.findBySn(sn));
    }
    @ApiOperation(value = "保存网络设备信息表", notes = "查询/更新网络设备信息表信息")
    @RequestMapping(value = "", method = RequestMethod.PUT)
    public WebResult saveMenu(
            @ApiParam(value = "提交信息") @RequestBody SubmitModel submitModel) {
        Integer result;
        try {
            result = service.saveWHNetEquipment(submitModel.getData(),
                    submitModel.getSn());
            if (result > 0) {
                return success("保存成功");
            } else {
                return fail("数据未保存");
            }
        } catch (Exception e) {
            return error(e);
        }
    }
    @ApiOperation(value = "删除网络设备信息表信息", notes = "根据网络设备信息表编号删除系网络设备信息表信息")
    @RequestMapping(path = "", method = RequestMethod.DELETE)
    public WebResult delete(
            @ApiParam(value = "网络设备信息表编号", name = "sn", allowMultiple = true, required = true)
            @RequestParam("sn") String[] sn) {
        if (service.delete(sn) > 0) {
            return success("删除成功");
        } else {
            return fail("删除失败");
        }
    }
    @ApiOperation(value = "查询网口设备信息表信息", notes = "查询网口设备信息表信息")
    @RequestMapping(path = "/querybynetsn/{sn}", method = RequestMethod.GET)
    public WebResult queryBynetSn(@ApiParam (value = "地磅设备信息表编号")  @PathVariable("sn") String sn){
        return  success("查询成功",service.queryListByDBSn(sn));
    }
}